﻿#pragma once

#include "Asset/Asset.h"

class CORE_API AssetManager
{
public:
  static AssetManager &GetInstance();

  template<typename T, typename... Args>
  static Ref<T> LoadAsset(const std::string &path, Args&&... args)
  {
    auto it = m_assets.find(path);
    if (it != m_assets.end()) { return std::dynamic_pointer_cast<T>(it->second); }
    Ref<T> asset = CreateRef<T>(path, std::forward<Args>(args)...);
    m_assets[path] = asset;
    return asset;
  }

  template<typename T>
  static Ref<T> GetAsset(const std::string &path)
  {
    auto it = m_assets.find(path);
    if (it != m_assets.end()) { return std::dynamic_pointer_cast<T>(it->second); }
    return nullptr;
  }

  void UnloadAll();

private:
  AssetManager() = default;

  static std::unordered_map<std::string, Ref<Asset>> m_assets;
};